from fastmcp import FastMCP

# 1. 创建服务器实例
mcp = FastMCP("demo-server")

# 2. 注册两个最简工具
@mcp.tool()
def greet(name: str) -> str:
    """Say hello to someone."""
    return f"Hello, {name}!"

@mcp.tool()
def calculate(a: float, b: float, op: str) -> float:
    """四则运算：op 支持 + - * /"""
    if op == "+":
        return a + b
    if op == "-":
        return a - b
    if op == "*":
        return a * b
    if op == "/":
        return a / b if b != 0 else float("nan")
    return float("nan")

# 3. 启动（HTTP 模式，监听 9000）
if __name__ == "__main__":
    mcp.run(transport="http", host="127.0.0.1", port=9000)